//
//  ViewController.m
//  CaLayerDemo
//
//  Created by student on 16/3/18.
//  Copyright © 2016年 NIIT. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()

@property (weak, nonatomic) IBOutlet UIImageView *imageView;

@property (nonatomic,weak) CALayer *layer;

@property (nonatomic,strong) UIView *moveView;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
    //圆角
    self.imageView.layer.cornerRadius = 50;
//    //边框
//    self.imageView.layer.borderColor = [UIColor yellowColor].CGColor;
//    //边框宽度
//    self.imageView.layer.borderWidth = 5;
//    self.imageView.layer.masksToBounds = YES;
    //阴影
//    self.imageView.layer.shadowColor = [UIColor blackColor].CGColor;
//    self.imageView.layer.shadowRadius = 15;
//    self.imageView.layer.shadowOffset = CGSizeMake(10, 10);
//    self.imageView.layer.shadowOpacity = 0.5f;
    
    CALayer *layer = [CALayer layer];
    layer.frame = CGRectMake(200, 150, 100, 100);
    layer.cornerRadius = 10;
    layer.masksToBounds = YES;
    layer.contents = (id)[UIImage imageNamed:@"2"].CGImage;
    [self .view.layer addSublayer:layer];
    
    self.moveView = [[UIView alloc] initWithFrame:CGRectMake(200, 300, 100, 100)];
    self.moveView.layer.cornerRadius = 10;
    self.moveView.layer.backgroundColor = [UIColor redColor].CGColor;
    [self.view addSubview:self.moveView];
    self.layer = self.moveView.layer;
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:2];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
    
    CGSize winSize = [UIScreen mainScreen].bounds.size;//屏幕的尺寸
    self.layer.position = CGPointMake(arc4random_uniform(winSize.width), arc4random_uniform(winSize.height));
    self.layer.cornerRadius = arc4random_uniform(1);
    self.layer.backgroundColor = [UIColor colorWithRed:arc4random_uniform(255)/255.0 green:arc4random_uniform(255)/255.0 blue:arc4random_uniform(255)/255.0 alpha:1].CGColor;
    self.layer.borderColor = [UIColor colorWithRed:arc4random_uniform(255)/255.0 green:arc4random_uniform(255)/255.0 blue:arc4random_uniform(255)/255.0 alpha:1].CGColor;
    self.layer.borderWidth = arc4random_uniform(1);
    self.layer.transform = CATransform3DMakeRotation(arc4random_uniform(M_PI*2), 0, 0, 1);
    
    [UIView commitAnimations];
}
@end
